<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel backend\models\SearchHouseModel */
/* @var $dataProvider yii\data\ActiveDataProvider */
?>
<div class="house-model-index">

    <p>
        <?php if (\backend\components\MenuHelper::checkRoute('create')) {
            echo Html::a('添加广告类型', ['create'], ['class' => 'btn btn-success']);
        } ?>
    </p>
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
            'tid',
            'typename',
            [
                'class' => 'yii\grid\ActionColumn',
                'template' => '' . \backend\components\MenuHelper::filterActionColumn('{update}&nbsp;&nbsp;{delete}'),
                'buttons' => [
                        'delete'=>function($url,$model){
                            return Html::a('<span class="glyphicon glyphicon-trash"></span>', '#', 
                            ['title' => '删除','class'=>'deleteclass','data'=>['url'=>$url]]);
                        }
                ]
            ],
        ],
    ]); ?>
	
    <?php
		$this->registerJs("
		$('.deleteclass').on('click', function () {	
			var msg = '您真的确定要删除吗？'; 
			if (confirm(msg)==true){ 
				deletefun($(this));
			}else{ 
				return false; 
			} 
				
		});
		function deletefun(deleteobj){
			var tohref = deleteobj.attr('data-url');	   
		    $.post(tohref, {},
		    	function (data) {
		    		var backobj = JSON.parse(data);
		            if(backobj.error!='ok'){
	                	alert(backobj.error);
	                }
                }
	        );
		}
		");
	?>
    
   
</div>
